package dre.sample.actions;

import java.util.ArrayList;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import dre.sample.beans.LoginBean;
import dre.sample.forms.LoginForm;

public class LoginAction extends Action{
	

    public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
    	
    	LoginForm loginForm = (LoginForm) form;
    	LoginBean bean = new LoginBean();
    	String link = "failure";
    	if(!(loginForm.getUserName() == null) || !(loginForm.getPassWord() == null) ||
        loginForm.getUserName().contains("@pointwest.com.ph") || !loginForm.getPassWord().equals("")){
    		bean.setUserName(loginForm.getUserName());
	    	loginForm.setUserName(bean.getUserName());
	    	link = "success";
    		return mapping.findForward(link);
    		//	return mapping.findForward("success");
	        
    	}
        else
    	{
        	link = "failure";
    		return mapping.findForward(link);
    		
	        //return mapping.findForward("failure");
    	}

    }
//	public ActionForward execute(
//		ActionMapping mapping,
//		ActionForm form,
//		HttpServletRequest request,
//		HttpServletResponse response)
//		throws Exception {
//			
//		String link = "success";
//		ActionMessages ams = new ActionMessages();
//		ActionMessage am = new ActionMessage("saved.thanks");
//		ams.add("INFO",am);
//		saveMessages(request, ams);
//		return mapping.findForward(link);
//	}

}
